﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Example_SeoulOpenAPI.ViewModels
{
    /// <summary>
    /// 역사 정보를 담은 ViewModel 클래스 / ViewModel class that have station information
    /// </summary>
    public class Station : INotifyPropertyChanged
    {
        /// <summary>
        /// 호선정보를 담은 문자배열 / String array of line numbers
        /// </summary>
        public static readonly string[] LineNums = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "J", "A", "G", "I", "K", "B" };

        private string _frCode;
        private string _lineName;
        private string _lineNum;
        private string _stationCode;
        private string _stationName;

        private Dictionary<string, string> _lineColor;

        public Station()
        {
            // init line color
            if (_lineColor == null) _lineColor = new Dictionary<string, string>();

            _lineColor.Add("1", "#0D3692");
            _lineColor.Add("2", "#33A23D");
            _lineColor.Add("3", "#FE5B10");
            _lineColor.Add("4", "#32A1C8");
            _lineColor.Add("5", "#8B50A4");
            _lineColor.Add("6", "#C55C1D");
            _lineColor.Add("7", "#54640D");
            _lineColor.Add("8", "#F51361");
            _lineColor.Add("9", "#AA9872");
            _lineColor.Add("J", "#32C6A6");
            _lineColor.Add("A", "#3681B7");
            _lineColor.Add("G", "#32C6A6");
            _lineColor.Add("I", "#8CADCB");
            _lineColor.Add("K", "#32C6A6");
            _lineColor.Add("B", "#FFB300");
        }

        #region Properties

        /// <summary>
        /// 역외부코드(일종의 식별번호 일반적으로 호선+일련번호의 형태를 띔: A01-공항철도 서울역)
        /// frCode(station code that is usually on information panel. Contains lineNumber and station number: A01 = Arex(A) + Seoul Station(01))
        /// </summary>

        public string FrCode
        {
            get { return _frCode; }
            set
            {
                if (value != _frCode)
                {
                    _frCode = value;
                    NotifyPropertyChanged("FrCode");
                }

            }
        }

        public string LineName
        {
            get { return _lineName; }
            set
            {
                if (_lineName != value)
                {
                    _lineName = value;
                    NotifyPropertyChanged("LineName");
                }
            }
        }

        public string LineNum
        {
            get { return _lineNum; }
            set
            {
                if (_lineNum != value)
                {
                    _lineNum = value;
                    NotifyPropertyChanged("LineNum");
                }
            }
        }

        public string StationCode
        {
            get { return _stationCode; }
            set
            {
                if (_stationCode != value)
                {
                    _stationCode = value;
                    NotifyPropertyChanged("StationCode");
                }
            }
        }

        public string StationName
        {
            get { return _stationName; }
            set
            {
                if (_stationName != value)
                {
                    _stationName = value;
                    NotifyPropertyChanged("StationName");
                }
            }
        }


        /// <summary>
        /// Read only
        /// </summary>
        [XmlIgnore]
        public string LineColor
        {
            get
            {
                return _lineColor[LineNum];
            }

            internal set
            {
                // do nothing
            }
        }

        #endregion

        #region Property Event

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
